#ifndef DETECTTHREAD_H
#define DETECTTHREAD_H
#include <QtCore>
#include <Windows.h>
#include "define.h"

#define ODBBUFFERLENGTH 1024

class DetectThread : public QThread
{
    Q_OBJECT
public:
    DetectThread();
    ~DetectThread();
    // 初始化,使用完成端口来处理多个等待对象异步的事情.
    bool init();
    // 添加到监视的路径.不存在且添加成功返回true
    bool addPath(QString path);
    // 存在并成功移除返回true
    bool removePath(QString path);
signals:
    void sgFileUpdate(QString path, FileUpdateType type);
protected:
    void run();
    bool asynReadChange(PathDetect *pd);
    void handleFileNotify(char* buffer, uint32_t len);
private:
    HANDLE hEvent_;
    struct OverlapData
    {
        OVERLAPPED overlap;  //must at top.
        char buffer[ODBBUFFERLENGTH];

    };
    class PathDetect{
    public:
        QString path;
        HANDLE hd;
        OverlapData *data;
    };

    QMap<QString,PathDetect*> paths_;
    HANDLE hdPort_;
};

#endif // DETECTTHREAD_H
